<template>
    <div class="home">
<el-container>
    <!-- 侧边栏 -->
  <el-aside width="auto">
      <div class="logo">
      </div>
      <el-menu
      default-active="2"
     :collapse="isCollapse"
     :router = true
      class="el-menu-admin"
      @open="handleOpen"
      @close="handleClose"
       background-color="#545c64"
      text-color="#fff"
      :unique-opened=true
      active-text-color="#ffd04b">
      <el-submenu :index="item.path" v-for="item in menuList" :key="item.id">
        <template slot="title">
          <i class="el-icon-location"></i>
          <span>{{item.authName}}</span>
        </template>
        <el-menu-item :index="item1.path" v-for="item1 in item.children" :key="item1.id">
             <i class="el-icon-menu"></i>
             <span slot="title">{{item1.authName}}</span>
          </el-menu-item>
      </el-submenu>
    </el-menu>
  </el-aside>
  <el-container>
      <!-- 右边头部 -->
    <el-header>
        <i class="myicon myicon-menu toggle-btn" @click="toggleBtn"></i>
        <div class="system-title">电商电台管理系统</div>
        <div>
            <span>欢迎，{{username}}</span>
            <el-button type="text" @click="layout">退出</el-button>
        </div>
    </el-header>
    <!-- 中间内容 -->
    <el-main>
        <router-view></router-view>
    </el-main>
  </el-container>
</el-container>
    </div>
</template>
<script>
import { getUserList,getMenus } from "@/api";
export default {
    data(){
        return{
            isCollapse:false,
            username:'',
            menuList:[]
        }
    },
    created(){
     this.username = localStorage.getItem('username')
    },
     methods: {
      handleOpen(key, keyPath) {
        console.log(key, keyPath);
      },
      handleClose(key, keyPath) {
        console.log(key, keyPath);
      },
      toggleBtn(){
          this.isCollapse = !this.isCollapse;
      },
      layout(){
        //   清除localstorage
          localStorage.removeItem('mytoken');
        //   跳转到登录页面
           this.$router.push({name:'Login'})
      }
    },
    created(){
    getMenus().then(res=>{
      if(res.meta.status == 200){
        this.menuList = res.data
      }else{
        this.$message({
          type:'error',
          message:res.meta.message
        })
      }
 
    })
    },
  mounted() {
    
    let params = { params: { query: "", pagenum: 1, pagesize: 1 } };
    getUserList(params).then(res => {
    //   console.log(res);
    });
  }
};
</script>
<style lang="scss" scoped>
.home {
  height: 100%;
  background-color: #e5e5e5;
  .el-menu-admin:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
  }
  .el-container {
    height: 100%;
  }
  .el-aside {
    background-color: #545c64;
  }
  .el-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #009688;
  }
  .logo {
    height: 60px;
    background: url(../assets/logo.png);
    background-size: cover;
    background-color: white;
  }
  .toggle-btn {
    padding: 0 10px;
    margin-left: -20px;
    font-size: 36px;
    line-height: 60px;
    color: #ccc;
    cursor: pointer;
    &:hover {
      background-color: #00635a;
    }
  }
  .system-title {
    font-size: 28px;
    color: white;
  }
  .welcome {
    color: white;
  }
}
</style>


